precision mediump float;

uniform sampler2D u_samplerBlend;
uniform sampler2D u_samplerTerrain1;
uniform sampler2D u_samplerTerrain2;
uniform sampler2D u_samplerTerrain3;
uniform vec4 u_fogColor;

varying vec2 v_uv;
varying float v_lerpValue;

void main()
{
	vec4 bt = texture2D(u_samplerBlend, v_uv);
	vec4 tex1 = texture2D(u_samplerTerrain1, v_uv);
	vec4 tex2 = texture2D(u_samplerTerrain2, v_uv);
	vec4 tex3 = texture2D(u_samplerTerrain3, v_uv);
	
	vec4 texColor = (bt.r*tex1 + bt.g*tex2 + bt.b*tex3)/(bt.r + bt.g + bt.b);
	gl_FragColor = v_lerpValue * u_fogColor + (1.0 - v_lerpValue) * texColor;
}
